/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-12     liuchao       the first version
 */
#define LOG_TAG "panel"
#include "drv_panel.h"
#include <ulog.h>

const char* panel_name(panel_e panel)
{
    switch (panel)
    {
    case PANEL_RED:
        return "RED";
    case PANEL_GREEN:
        return "GREEN";
    case PANEL_YELLOW:
        return "YELLOW";
    case PANEL_BEEP:
        return "BEEP";
    default:
        return "UNKNOWN";
    }
}

static void panel_init(panel_e panel)
{
    switch (panel)
    {
    case PANEL_RED:
        rt_pin_mode(PANEL_RED_PIN, PIN_MODE_OUTPUT);
        rt_pin_write(PANEL_RED_PIN, PIN_LOW);
        break;
    case PANEL_GREEN:
        rt_pin_mode(PANEL_GREEN_PIN, PIN_MODE_OUTPUT);
        rt_pin_write(PANEL_GREEN_PIN, PIN_LOW);
        break;
    case PANEL_YELLOW:
        rt_pin_mode(PANEL_YELLOW_PIN, PIN_MODE_OUTPUT);
        rt_pin_write(PANEL_YELLOW_PIN, PIN_LOW);
        break;
    case PANEL_BEEP:
        rt_pin_mode(PANEL_BEEP_PIN, PIN_MODE_OUTPUT);
        rt_pin_write(PANEL_BEEP_PIN, PIN_LOW);
        break;
    default:
        break;
    }
}

void panel_on(panel_e panel)
{
    switch (panel)
    {
    case PANEL_RED:
        rt_pin_write(PANEL_RED_PIN, PIN_HIGH);
        break;
    case PANEL_GREEN:
        rt_pin_write(PANEL_GREEN_PIN, PIN_HIGH);
        break;
    case PANEL_YELLOW:
        rt_pin_write(PANEL_YELLOW_PIN, PIN_HIGH);
        break;
    case PANEL_BEEP:
        rt_pin_write(PANEL_BEEP_PIN, PIN_HIGH);
        break;
    default:
        LOG_E("Invalid panel %d", panel);
        break;
    }
}
void panel_off(panel_e panel)
{
    switch (panel)
    {
    case PANEL_RED:
        rt_pin_write(PANEL_RED_PIN, PIN_LOW);
        break;
    case PANEL_GREEN:
        rt_pin_write(PANEL_GREEN_PIN, PIN_LOW);
        break;
    case PANEL_YELLOW:
        rt_pin_write(PANEL_YELLOW_PIN, PIN_LOW);
        break;
    case PANEL_BEEP:
        rt_pin_write(PANEL_BEEP_PIN, PIN_LOW);
        break;
    default:
        LOG_E("Invalid panel %d", panel);
        break;
    }
}

static int init_panel()
{
    for (int i = PANEL_START; i < PANEL_END; i++)
    {
        panel_init(i);
    }
    return RT_EOK;
}
INIT_COMPONENT_EXPORT(init_panel);
